package com.example.my_helper;

import android.util.Log;

import java.math.BigInteger;

public class Register {
    public String[] register_class_strs = new String[]{"线圈状态", "离散输入", "保持寄存器", "输入寄存器"};

    public long id1;
    public String register_name;
    public String device_addr_str;
    public String register_type_str;
    public String register_addr_str;
    public int device_addr;
    public int register_addr;
    public int register_num;
    public int register_class;
    public int data_type;
    public int bit_offset;
    public int bit_width;
    public float ratio;
    public int period;
    public long time_tick = 0;
    public boolean swapped;
    public boolean hex_show;
    public String unit;
    public String update_time;
    public String value_str;
    public Long value_long;
    public BigInteger value_ulong;
    public Float value_float;
    public Double value_double;
    public Short value_short;
    public Integer value_ushort;
    public Integer value_int;
    public Long value_uint;
    public Boolean value_boolean;
    public int value_binary;

    public Register() {
    }

    public Register(String register_name, int register_type, String register_addr, String value, String updata) {
        this.register_name = register_name;
        setRegister_type(register_type);
        this.register_addr_str = register_addr;
        this.value_str = value;
        this.update_time = updata;
    }

    public String getRegister_name() {
        return register_name;
    }

    public void setRegister_name(String name) {
        this.register_name = name;
    }

    public String getRegister_addr() {
        return register_addr_str;
    }

    public void setRegister_type(int type){
        this.register_class = type;
        this.register_type_str = register_class_strs[type];
    }

    public void setRegister_addr(String s) {
        String s1 = s.toLowerCase();
        if(s1.startsWith("0x")){
            s = s1.substring(2);
            this.register_addr = Integer.parseInt(s, 16);
        }else{
            this.register_addr = Integer.parseInt(s);
        }
        this.register_addr_str = s1;
    }

    public String getRegister_type_str() {
        return register_type_str;
    }

    public void setDevice_addr(String s) {
        String s1 = s.toLowerCase();
        if(s1.startsWith("0x")){
            s = s1.substring(2);
            this.device_addr = Integer.parseInt(s, 16);
        }else{
            this.device_addr = Integer.parseInt(s);
        }
        device_addr_str = s1;
    }

    public String getUpdate_time() {
        return update_time;
    }

    public String getValue() {
        return value_str;
    }


}
